package com.adaxi.adc.business.manager.config;

import com.adaxi.adc.business.manager.filter.GateWayWallIntercepter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @param
 * @author 涛哥
 * @version 1.0
 * @ClassName:Name
 * @description:TODO
 * @date 2023/9/29 17:53
 */
@EnableWebMvc
@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {


    @Value("${my.uploadFilePath}")
    String  filepath;


    @Autowired
    GateWayWallIntercepter gateWayWallIntercepter;



    /**
     * 静态资源的
     * <img src="http://localhost:8080/static/image.jpg" />
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations(
                "classpath:/static/","file:/"+filepath);
        registry.addResourceHandler("swagger-ui.html").addResourceLocations(
                "classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations(
                "classpath:/META-INF/resources/webjars/");
        //WebMvcConfigurer.super.addResourceHandlers(registry);
    }


    /**
     * 添加拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
       registry.addInterceptor(gateWayWallIntercepter).addPathPatterns("/**");

    }

}
